package my.maven.project.spiderproc.controller;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import my.maven.project.spiderproc.entity.Person;
import my.maven.project.spiderproc.service.IPersonService;
import my.maven.project.spiderproc.service.impl.PersonServiceImpl;

@RestController
@RequestMapping("/p")
public class PersonController {

	@Autowired
	private IPersonService personService;
	
	@GetMapping("/add")
	public String add(String n,int a)
	{
		Person entity = new Person();
		entity.setId( UUID.randomUUID().toString());
		entity.setName(n);
		entity.setAge(a);
		entity.setCreateDate(new Date());
		personService.add(entity);
		return "ok";
	}
	
	@GetMapping("/list")
	public List<Person> list()
	{
		return personService.getList();
	}
	
	@GetMapping("/addp")
	public String addNewPersonWord(String n,int a) 
	{
		Person entity = new Person();
		entity.setId( UUID.randomUUID().toString());
		entity.setName(n);
		entity.setAge(a);
		entity.setCreateDate(new Date());
		try {
			personService.addNewPersonWord(entity);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "ok";
	}
	
	
	
}
